using UnityEngine;

public class EnemyCharacter : Character {
    [HideInInspector] public Collider2D coll; 
    public ParticleSystem knifeLightEffects;

    private void Awake() {
        coll = GetComponent<Collider2D>();
    }

    // 受伤逻辑
    protected override void Hit(Attack attack)
    {
        GetComponent<EnemyFSM>().parameter.isHurt = true;

        //时停
        TimeManager.Instance.BulletTime(0.2f, 0.5f);

        //击退
        float direction = transform.position.x - attack.transform.parent.position.x > 0 ? 1 : -1;//击退方向
        rb.velocity = new Vector2(backPosition.x * direction, backPosition.y);

        //受击特效
        hitEffects.Play();

        //伤害飘字
        GameManager.Instance.ShowText(attack.damage.ToString(), transform, Color.red);

        //屏幕抖动
        GameManager.Instance.CameraShake();

        //刀光
        knifeLightEffects.Play();
    }

    // 死亡逻辑
    protected override void Die()
    {
        GetComponent<EnemyFSM>().parameter.isDead = true;
        isDead = true;
        //取消碰撞
        // coll.enabled = false;
        //死亡特效
        dieEffects.Play();
        Destroy(gameObject, 2f);
    }
}
